Skip to content

Conversation

@ianbotsf
Copy link
Contributor

@ianbotsf ianbotsf commented Feb 5, 2025

Issue #

(none)

Description of changes

Fix for #1233 (comment)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ianbotsf ianbotsf requested a review from a team as a code owner February 5, 2025 18:16
@github-actions

This comment has been minimized.

Comment on lines 37 to 43
override val entries: MutableSet<MutableMap.MutableEntry<String, Value>>
get() = impl.entries.map {
Entry(it.key.s, it.value)
Entry(it.key.normalized, it.value)
}.toMutableSet()

override val keys: MutableSet<String>
get() = impl.keys.map { it.s }.toMutableSet()
get() = impl.keys.map { it.normalized }.toMutableSet()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes mean that tests like the following will fail:

    @Test
    fun testSimpleKeyOp() {
        val map = CaseInsensitiveMap<String>()
        map["A"] = "apple"
        assertTrue(map.keys.contains("A"))
    }

Is that expected from a case insensitive map? I think the keys should remain unmodified, they should only be case-insensitive for equality operations.

Maybe both map.keys.contains("A") and map.keys.contains("a") should be true.

Copy link
Contributor Author

@ianbotsf ianbotsf Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, they should both be true. Revision incoming...

Wait, maybe not. The return type of keys is MutableSet<String> which cannot comprehend case-insensitivity.

Actually that probably just means we're missing a CaseInsensitiveSet abstraction.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment on lines +19 to +20
override fun addAll(elements: Collection<String>) =
elements.fold(false) { modified, item -> add(item) || modified }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to elements.any { add(it) }, same applies for removeAll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, any short-circuits once it finds a match. If we used that, we'd only ever add at most a single item.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. I updated the implementation before posting this comment and all the tests still passed, but it's probably just the way they're written

@@ -0,0 +1,11 @@
package aws.smithy.kotlin.runtime.collections

internal class CaseInsensitiveString(val original: String) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests for CaseInsensitiveString. It is tested indirectly through the other classes though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested indirectly but you're right, it'd be better to have dedicated tests. Will add!

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link

github-actions bot commented Feb 6, 2025

Affected Artifacts

Changed in size
Artifact Pull Request (bytes) Latest Release (bytes) Delta (bytes) Delta (percentage)
aws-signing-default-jvm.jar 53,497 51,946 1,551 2.99%
runtime-core-jvm.jar 825,482 818,814 6,668 0.81%

@ianbotsf ianbotsf merged commit 5323882 into main Feb 6, 2025
16 checks passed
@ianbotsf ianbotsf deleted the fix-caseinsensitivemap-equality branch February 6, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants